package studiodiva.portfolio.client.lib.history;

import studiodiva.portfolio.client.lib.lang.Base;

class HistoryItemImpl extends Base implements HistoryItem {

  private final String defaultValue;
  private final String key;
  private String value;

  public HistoryItemImpl(String key, String defaultValue) {
    this.key = key;
    this.defaultValue = defaultValue;
  }

  public String getKey() {
    return key;
  }

  public String getValue() {
    return value;
  }

  public void load(String value) {
    if (this.value == value) return;
    save(value);
    fireEvent(ON_CHANGE, value);
  }

  public void loadDefault() {
    load(defaultValue);
  }

  @Override
  public void save(String value) {
    this.value = value;
  }
}
